/***************************************************************************
 *   Copyright (C) 2010 by programmeboy                                    *
 *   programmeboy@gmail.com                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
 ***************************************************************************/

#include "io.h"
#include "disk.h"

int read_mbr( PUINT64_STRUCT sector, char drive, char* buffer )
{
	int n_ret = 1;
	BIOS_LBA_PACKET bios_pack = {0};
	if ( !is_lba_support( drive ) ){
		
	}

	bios_pack.size = sizeof( BIOS_LBA_PACKET );
	bios_pack.sector = sector->Value;	
	bios_pack.sector_count = 1;
	bios_pack.buffer = buffer;

	__asm
	{
		mov	bx, 0x55aa
		mov	dl, drive
		mov si, [bios_pack]
		mov	ah, 0x42
		xor al, al
		int	0x13
		jnc ok				// If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
		mov	n_ret, ah
ok:
	}

	if ( n_ret == 0x11 ){
		n_ret = 1;
	}
	
	return n_ret;
}